Combo box callback (mis)behavior

If I have a choice DBE that is readonly, the activate callback gives me the selected value:

  • select "One", callback shows "One"
  • select "Two" callback shows "Two"
  • ...

If I use a choice DBE that is editable, the active callback gives me the previous selected value:

  • select "One", callback shows nothing
  • select "Two", callback shows "One"
  • select "Five", callback shows "Two"
  • ...

How can I use the callback on a editable choice DBE (aka combo box)?

 

/**
 * Created by: sturm
 * Creation date: 09.01.2017
 *
 */
pragma encoding, "UTF-8"

string Choices[] = {"One", "Two", "Three", "Four", "Five"}

void callBack(DBE elem)
{
        string val = get(elem)
        print "callBack(DBE): '" val "'\n"
}

DB Box = create "Choice Example"

DBE Ch = choice(Box, "Choice", Choices, 0, 20, true) //false)

set(Ch, callBack)

show Box

 


thsturm - Mon Jan 09 10:41:55 EST 2017

Re: Combo box callback (mis)behavior
Mathias Mamsch - Tue Jan 10 05:10:50 EST 2017

Since when the callback is fired the value is not yet applied for editable combos you get the current value, when you call "get". To get the selected value you need to get the selected index: 

pragma encoding, "UTF-8"

string Choices[] = {"One", "Two", "Three", "Four", "Five"}

void callBack(DBE elem)
{
        int index = get(elem);
      string val = Choices[index];
      print "callBack(DBE): '" val "'\n"
}

DB Box = create "Choice Example"
DBE Ch = choice(Box, "Choice", Choices, 0, 20, true) //false)
set(Ch, callBack)
show Box

I think there is no callback that will fire, when the user types inside the input field. You can use a text field in combination with a list if you need that. People have also successfully worked with timers polling the value of the combobox for changes. 

maybe that helps, regards, Mathias

Re: Combo box callback (mis)behavior
thsturm - Tue Jan 10 06:02:57 EST 2017

Mathias Mamsch - Tue Jan 10 05:10:50 EST 2017

Since when the callback is fired the value is not yet applied for editable combos you get the current value, when you call "get". To get the selected value you need to get the selected index: 

pragma encoding, "UTF-8"

string Choices[] = {"One", "Two", "Three", "Four", "Five"}

void callBack(DBE elem)
{
        int index = get(elem);
      string val = Choices[index];
      print "callBack(DBE): '" val "'\n"
}

DB Box = create "Choice Example"
DBE Ch = choice(Box, "Choice", Choices, 0, 20, true) //false)
set(Ch, callBack)
show Box

I think there is no callback that will fire, when the user types inside the input field. You can use a text field in combination with a list if you need that. People have also successfully worked with timers polling the value of the combobox for changes. 

maybe that helps, regards, Mathias

Thank you, this a solution for fixed choices.

But if you create the choices dynamically or even use the combo box as editable field, there is no such solution :-(

If you edit the combo box, you will get the edited value on the folloing call of the callback.

  • select "One", callback gives ""
  • edit "Hello", callback gives "One"
  • select "Two", callback gives "Hello"
  • ..., callback gives "Two"

The question remains:how can I get the actual value of a combo box in a callback?

Re: Combo box callback (mis)behavior
Mathias Mamsch - Tue Jan 10 06:47:22 EST 2017

thsturm - Tue Jan 10 06:02:57 EST 2017

Thank you, this a solution for fixed choices.

But if you create the choices dynamically or even use the combo box as editable field, there is no such solution :-(

If you edit the combo box, you will get the edited value on the folloing call of the callback.

  • select "One", callback gives ""
  • edit "Hello", callback gives "One"
  • select "Two", callback gives "Hello"
  • ..., callback gives "Two"

The question remains:how can I get the actual value of a combo box in a callback?

Did you try: 

int index = get (elem)
string sValue = get(elem, index);

or something like this? Apart form that even if you dynamically generate the choices, you will be able to keep track about what is inside your combobox. If you do not think thats possible, can you give an example of what exactly your GUI is supposed to do? 

Regards, Mathias

Re: Combo box callback (mis)behavior
thsturm - Tue Jan 10 07:48:22 EST 2017

Mathias Mamsch - Tue Jan 10 06:47:22 EST 2017

Did you try: 

int index = get (elem)
string sValue = get(elem, index);

or something like this? Apart form that even if you dynamically generate the choices, you will be able to keep track about what is inside your combobox. If you do not think thats possible, can you give an example of what exactly your GUI is supposed to do? 

Regards, Mathias

Thank you, this 'double trick' did it. Smile